<?php
if ($model->widget->type == WidgetDefinition::TYPE_REQUIRED)
{
    $script = "
jQuery(function(){
    jQuery('body').delegate('.page-list input', 'click', function(){
        var page_id = jQuery(this).val();
        if (jQuery(this).attr('checked'))//create instance
        {
            var url = '".$this->createUrl('/Core/service/ajax', array('SID'=>'Cms.PageWidget.addRequiredWidget', 'widget_id'=>$model->widget_id))."';
            jQuery.get(url, {page_id: page_id}, function(){
                
            });
        }
        else//remove instance
        {
            var url = '".$this->createUrl('/Core/service/ajax', array('SID'=>'Cms.PageWidget.deleteByPageIdAndWidgetId', 'widget_id'=>$model->widget_id))."';
            jQuery.get(url, {page_id: page_id}, function(){
                
            });
        }
    });
});
";
    Yii::app()->clientScript->registerScript(__CLASS__.'#UpdateInstances', $script);
}
$tabs = array('Layout Info'=>$this->renderPartial('_info_layout', array('model'=>$model), true));
if ($model->widget->type != WidgetDefinition::TYPE_STATIC)
{
    $tabs['Instances'] = array('ajax'=>$this->createUrl('/Cms/admin/widget/instancesUsedLayout', array('widget_layout_id'=>$model->id)));
    $tabs['Pages'] = array('ajax'=>$this->createUrl('/Cms/admin/widget/pagesUsedLayout', array('widget_id'=>$model->widget_id, 'widget_layout_id'=>$model->id,'is_required'=>($model->widget->type == WidgetDefinition::TYPE_REQUIRED ? 1 : 0))));
}
$this->widget('zii.widgets.jui.CJuiTabs', array(
    'tabs'=>$tabs,
    'options'=>array(
        'cache'=>true,
    ),
));